<template>
	<view>
    <u-button @click="onBuy">buy</u-button>
    <u-button @click="onProduct">product</u-button>
    <view>
      {{ $store.getters['User/token'] }}
    </view>
    <view>
      {{token}}
    </view>
    <view>
      {{title}}
    </view>
  </view>
</template>

<script>

/*

  这个不删除是为了测试 uniapp 一些写法

 */

import Request from '../../util/request'
import base64 from '@/util/base64'
import { save, get } from '@/util/cache'
import { mapGetters } from 'vuex'

const request = new Request()

	export default {
  // 小程序需要用这种方式获取
    computed: {
      ...mapGetters({
        token: 'User/token'
      })
    },
		data() {
			return {
				title: 'Hello'
			}
		},
		onShow() {
      this.$store.dispatch('User/login', 'aabbcc')
      // console.log(this.$store.getters['User/token'])
      request.test().then(response => {
        console.log(response.data)
        this.title = response.data.title
      })
		},
		methods: {
			onBuy() {
				uni.navigateTo({
					url: '/sub_main/buy/index'
				})
			},
			onProduct() {
				uni.switchTab({
					url: '/pages/category/index?id=2'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.content {
  height: 10100px;
  background: black;
  margin-top: 10px;
}
</style>
